home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
gui
/
pastbrowser.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
18KB
|
476 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
import wx
from gui import skin
from gui.uberwidgets.PrefPanel import PrefPanel
from gui.uberwidgets.UberCombo import UberCombo
from gui.uberwidgets.simplemenu import SimpleMenuItem
from gui.uberwidgets.UberButton import UberButton
from gui.toolbox import persist_window_pos, snap_pref
from gui.browser.webkit import WebKitWindow
from cgui import SimplePanel
from util import Storage
from common import logger
import logging
log = logging.getLogger('pastbrowser')
from wx import ALL, TOP, BOTTOM, LEFT, EXPAND, ALIGN_CENTER_VERTICAL, ALIGN_LEFT, ALIGN_RIGHT, VERTICAL, HORIZONTAL, WHITE, WHITE_BRUSH, TRANSPARENT_PEN, Color, BoxSizer, Brush, Rect
TOPLESS = ALL & ~TOP
BUTTON_SKIN = 'AppDefaults.PastButton'
from wx import DateTimeFromDMY
from wx.calendar import CAL_SUNDAY_FIRST, CAL_SEQUENTIAL_MONTH_SELECTION, CAL_SHOW_HOLIDAYS, EVT_CALENDAR_MONTH, EVT_CALENDAR_YEAR, EVT_CALENDAR_SEL_CHANGED, CalendarCtrl, CalendarDateAttr
def logpath_for_date(buddy, date):
year = '%d' % int(date.GetYear())
month = '%02d' % (date.GetMonth() + 1)
day = '%02d' % int(date.GetDay())
return buddy.dir / ''.join([
year,
'-',
month,
'-',
day,
'.html'])
def MakeAccountItems():
logdir = logger.get_default_logging_dir()
protodirs = logdir.dirs()
accts = { }
for protodir in protodirs:
accts[protodir.name] = [ dir.name for dir in protodir.dirs() ]
items = []
for proto in accts:
try:
protoicon = skin.get('serviceicons.' + proto, None).ResizedSmaller(16)
except Exception:
[]
[]
[]
continue
except:
[]
for acct in accts[proto]:
items.append(SimpleMenuItem([
protoicon,
acct], id = logdir / proto / acct))
return items
def GetBuddies(acctdir):
buddies = []
for bdir in acctdir.dirs():
try:
(name, service) = bdir.name.rsplit('_', 1)
serviceicon = skin.get('serviceicons.' + service, None).ResizedSmaller(16)
except Exception:
continue
buddies.append(Storage(icon = serviceicon, name = name, service = service, dir = bdir))
return buddies
def GetDates(logdir):
dates = []
append = dates.append
for logfile in logdir.files():
datestring = logfile.name
try:
(y, m, d) = datestring[:datestring.rfind('.')].split('-')
y = int(y)
m = int(m) - 1
d = int(d)
except Exception:
continue
append(DateTimeFromDMY(d, m, y))
return sorted(dates)
bgcolors = [
wx.Color(239, 239, 239),
wx.Color(255, 255, 255)]
hovbgcolor = wx.Color(220, 220, 220)
def SelectAccountByDir(acctdir, combo):
for item in combo:
if acctdir == item.id:
combo.SetSelection(combo.GetIndex(item))
return True
continue
return False
class ListOBuddies(wx.VListBox):
def __init__(self, parent):
wx.VListBox.__init__(self, parent, -1)
self.buddies = []
self.Hovered = -1
self.SetItemCount(0)
self.itemheight = max(self.Font.Height, 16) + 10
self.date = None
Bind = self.Bind
Bind(wx.EVT_MOTION, self.OnMotion)
def OnMotion(self, event):
rect = self.ClientRect
wap = wx.FindWindowAtPointer()
mp = event.Position
hit = self.HitTest(mp)
if not rect.Contains(mp) or not (wap == self):
while self.HasCapture():
self.ReleaseMouse()
self.Hovered = -1
self.Refresh()
return None
elif not self.HasCapture():
self.CaptureMouse()
self.Hovered = hit
self.Refresh()
def OnDrawBackground(self, dc, rect, n):
if self.Selection == n:
dc.Brush = Brush(wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT))
elif self.Hovered == n:
pass
dc.Brush = Brush(bgcolors[n % len(bgcolors)])
dc.Pen = wx.TRANSPARENT_PEN
dc.DrawRectangleRect(rect)
def OnDrawItem(self, dc, rect, n):
dc.Font = self.Font
dc.TextForeground = None if self.Selection == n else wx.BLACK
buddy = self.buddies[n]
x = rect.x + 3
y = rect.y + rect.height // 2 - 8
dc.DrawBitmap(buddy.icon, x, y, True)
textrect = Rect(x + 16 + 3, rect.y, rect.Width - x - 38, rect.Height)
dc.DrawLabel(buddy.name, textrect, ALIGN_CENTER_VERTICAL | ALIGN_LEFT)
def OnMeasureItem(self, n):
return self.itemheight
def SetList(self, buddies):
self.buddies = buddies
self.SetItemCount(len(self.buddies))
if self.ItemCount:
self.SetSelection(0)
wx.CallAfter(self.Refresh)
def SelectedBuddy(self):
return self.buddies[self.Selection]
SelectedBuddy = property(SelectedBuddy)
def SelectBuddy(self, service, name):
found = -1
for i, buddy in enumerate(self.buddies):
if buddy.name == name and buddy.service == service:
found = i
break
continue
self.Selection = found
if found != -1:
self.ProcessEvent(wx.CommandEvent(wx.wxEVT_COMMAND_LISTBOX_SELECTED))
self.Refresh()
return True
else:
self.Refresh()
return False
class BlatantFirefoxRipoff(wx.Panel):
def __init__(self, parent, viewer):
wx.Panel.__init__(self, parent)
self.viewer = viewer
find_label = wx.StaticText(self, -1, _('Find'))
self.TextControl = find_input = wx.TextCtrl(self, -1, size = (180, -1), style = wx.TE_PROCESS_ENTER)
nextbutton = self.nextbutton = UberButton(self, label = 'Next', skin = 'AppDefaults.PastButton')
prevbutton = self.prevbutton = UberButton(self, label = 'Prev', skin = 'AppDefaults.PastButton')
sz = self.Sizer = wx.BoxSizer(wx.HORIZONTAL)
sz.AddMany([
(find_label, 0, TOP | BOTTOM | LEFT | ALIGN_CENTER_VERTICAL | ALIGN_RIGHT, 6),
(find_input, 0, TOP | BOTTOM | LEFT | ALIGN_CENTER_VERTICAL, 6),
(nextbutton, 0, TOP | BOTTOM | LEFT | ALIGN_CENTER_VERTICAL | EXPAND, 6),
(prevbutton, 0, TOP | BOTTOM | LEFT | ALIGN_CENTER_VERTICAL | EXPAND, 6)])
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
Bind = self.Bind
Bind(wx.EVT_PAINT, self.OnPaint)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
fiBind = find_input.Bind
fiBind(wx.EVT_TEXT, self.OnFindText)
fiBind(wx.EVT_KEY_DOWN, self.OnFindKey)
nextbutton.Bind(wx.EVT_BUTTON, self.OnFindText)
prevbutton.Bind((wx.EVT_BUTTON,), (lambda e: self.OnFindText(e, False)))
def OnFindKey(self, e):
c = e.KeyCode
if (c in (wx.WXK_RETURN, wx.WXK_F3) or c == ord('G')) and e.GetModifiers() in (wx.MOD_CMD, wx.MOD_CMD + wx.MOD_SHIFT):
self.OnFindText(forward = not e.ShiftDown())
self.TextControl.SetFocus()
else:
e.Skip()
def OnFindText(self, e = None, forward = True):
self.viewer.FindString(self.TextControl.Value, forward, False, True, True)
def OnPaint(self, event):
rect = wx.RectS(self.ClientSize)
dc = wx.BufferedPaintDC(self)
dc.Brush = wx.WHITE_BRUSH
dc.Pen = wx.Pen(wx.Color(213, 213, 213))
dc.DrawRectangleRect(rect)
class PastBrowserPanel(SimplePanel):
def __init__(self, parent):
SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE)
self.BackgroundColour = WHITE
self.Sizer = wx.BoxSizer(HORIZONTAL)
sz = wx.BoxSizer(HORIZONTAL)
self.Sizer.Add(sz, 1, EXPAND | ALL, 3)
leftcol = wx.BoxSizer(VERTICAL)
acctcombo = self.acctcombo = UberCombo(self, value = '', skinkey = 'AppDefaults.PrefCombo')
acctcont = PrefPanel(self, acctcombo, 'Account')
leftcol.Add(acctcont, 0, EXPAND | ALL, 3)
buddylist = self.buddylist = ListOBuddies(self)
buddycont = PrefPanel(self, buddylist, 'Buddy')
leftcol.Add(buddycont, 1, EXPAND | TOPLESS, 3)
style = wx.NO_BORDER | CAL_SUNDAY_FIRST | CAL_SEQUENTIAL_MONTH_SELECTION | CAL_SHOW_HOLIDAYS
cal = self.cal = CalendarCtrl(self, -1, wx.DateTime.Now(), wx.DefaultPosition, wx.DefaultSize, style)
cal.SetForegroundColour(wx.Color(160, 160, 160))
cal.SetHolidayColours(wx.BLACK, wx.WHITE)
cal.SetHeaderColours(Color(160, 160, 160), Color(239, 239, 239))
calcont = PrefPanel(self, cal, 'Date')
leftcol.Add(calcont, 0, EXPAND | TOPLESS, 3)
sz.Add(leftcol, 0, EXPAND)
viewpanel = wx.Panel(self)
viewer = self.viewer = WebKitWindow(viewpanel)
finder = self.finder = BlatantFirefoxRipoff(viewpanel, viewer)
viewer.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
finder.TextControl.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
nav = BoxSizer(wx.HORIZONTAL)
prev = self.prev = UberButton(viewpanel, label = '<-', skin = BUTTON_SKIN)
next = self.next = UberButton(viewpanel, label = '->', skin = BUTTON_SKIN)
datelabel = wx.StaticText(viewpanel, -1, style = wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE)
datelabel.SetMinSize((140, -1))
prev.Bind((wx.EVT_BUTTON,), (lambda e: self.Flip(-1)))
next.Bind((wx.EVT_BUTTON,), (lambda e: self.Flip(1)))
nav.AddStretchSpacer(1)
nav.AddMany([
(prev, 0, wx.EXPAND | wx.ALIGN_CENTER),
(datelabel, 0, wx.EXPAND | wx.ALIGN_CENTER),
(next, 0, wx.EXPAND | wx.ALIGN_CENTER)])
nav.AddStretchSpacer(1)
viewpanel.Sizer = wx.BoxSizer(wx.VERTICAL)
viewpanel.Sizer.AddMany([
(nav, 0, EXPAND),
(viewer, 1, EXPAND),
(finder, 0, EXPAND)])
sz.Add(PrefPanel(self, viewpanel, _('Conversation Log')), 1, EXPAND | ALL, 3)
Bind = self.Bind
Bind(wx.EVT_PAINT, self.OnPaint)
def OnAcct(*a):
buddylist.SetList(GetBuddies(acctcombo.Value.id))
OnBuddy()
def OnBuddy(*a):
self.dates = GetDates(buddylist.SelectedBuddy.dir)
self.next.Enable(True)
self.prev.Enable(True)
self.cal.Enable(True)
OnCalChange()
def OnCalChange(*a):
caldate = cal.Date
currentyear = caldate.GetYear()
currentmonth = caldate.GetMonth()
relevantdates = (None, frozenset)((lambda .0: for date in .0:
if date.GetYear() == currentyear and date.GetMonth() == currentmonth and date.GetDay():
date.GetDay()continue)(self.dates))
SetHoliday = cal.SetHoliday
SetAttr = cal.SetAttr
for i in xrange(1, 32):
if i in relevantdates:
SetHoliday(i)
continue
SetAttr(i, CalendarDateAttr(Color(160, 160, 160)))
OnDayChange()
self.OnCalChange = OnCalChange
def OnDayChange(*a):
date = cal.Date
self.date = date
datelabel.SetLabel(date.FormatDate())
if cal.GetAttr(date.GetDay()).IsHoliday():
logpath = logpath_for_date(buddylist.SelectedBuddy, date)
viewer.Frozen().__enter__()
try:
viewer.SetPageSource(logpath.text('utf-8', 'replace'), logpath.url())
viewer.RunScript('window.scroll(0, 0);')
finally:
pass
else:
year = str(date.GetYear())
month = date.GetMonth()
month = wx.DateTime.GetMonthName(int(month))
day = str(date.GetDay())
viewer.SetPageSource('There are no chat logs for %s %s, %s with %s.' % (month, day, year, buddylist.SelectedBuddy.name), 'file:///C:/')
wx.CallAfter(cal.Refresh)
self.OnDayChange = OnDayChange
acctcombo.SetCallbacks(value = OnAcct)
buddylist.Bind(wx.EVT_LISTBOX, OnBuddy)
cBind = cal.Bind
cBind(EVT_CALENDAR_YEAR, OnCalChange)
cBind(EVT_CALENDAR_MONTH, OnCalChange)
cBind(EVT_CALENDAR_SEL_CHANGED, OnDayChange)
acctcombo.SetItems(MakeAccountItems(), 0)
def OnKeyDown(self, event):
KeyCode = event.KeyCode
if KeyCode == wx.WXK_PAGEDOWN:
self.viewer.ScrollPages(1)
elif KeyCode == wx.WXK_PAGEUP:
self.viewer.ScrollPages(-1)
else:
event.Skip()
def Flip(self, delta):
log.info('Flip(%s)', delta)
log.info(' self.dates: %r', self.dates)
dates = self.dates
date = self.date
try:
foundIndex = dates.index(date) + delta
except ValueError:
alldates = [
DateTimeFromDMY(1, 1, 1900)] + dates + [
DateTimeFromDMY(20, 10, 3000)]
foundIndex = len(dates) - 1
for i in xrange(1, len(alldates)):
if date.IsStrictlyBetween(alldates[i - 1], alldates[i]):
foundIndex = None if delta < 0 else i
break
continue
foundIndex = max(0, min(len(dates) - 1, foundIndex))
self.cal.SetDate(dates[foundIndex])
self.OnCalChange()
def OnPaint(self, event):
rect = wx.RectS(self.Size)
dc = wx.PaintDC(self)
dc.Brush = WHITE_BRUSH
dc.Pen = TRANSPARENT_PEN
dc.DrawRectangleRect(rect)
def OpenBuddyHistory(self, acctdir, acct, name, service):
if not SelectAccountByDir(acctdir, self.acctcombo):
self.next.Enable(False)
self.prev.Enable(False)
self.cal.Enable(False)
return self.NoHistory(name, service, acct)
def AfterOpenBuddyHistory():
if not self.buddylist.SelectBuddy(service, name):
self.next.Enable(False)
self.prev.Enable(False)
self.cal.Enable(False)
return self.NoHistory(name, service, acct)
self.next.Enable(True)
self.prev.Enable(True)
self.cal.Enable(True)
self.Flip(1)
wx.CallAfter(AfterOpenBuddyHistory)
def NoHistory(self, name, service, acct):
self.viewer.SetPageSource('There is no chat history for %s on %s with %s.' % (name, service, acct), 'file:///C:/')
class PastBrowser(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, _('Past Chat Browser'), name = 'Past Chat Browser')
self.SetFrameIcon(skin.get('appdefaults.taskbaricon'))
sz = self.Sizer = wx.BoxSizer(VERTICAL)
self.pastbrowser = PastBrowserPanel(self)
sz.Add(self.pastbrowser, 1, EXPAND)
persist_window_pos(self, defaultrect = (150, 150, 700, 500))
snap_pref(self)
def MakeOrShow(cls):
win = PastBrowser.RaiseExisting()
if win is None:
win = PastBrowser()
wx.CallAfter(win.Show)
return win
MakeOrShow = classmethod(MakeOrShow)
def MakeOrShowAndSelect(cls, buddydir):
acctdir = buddydir.parent
acct = acctdir.name
(name, service) = buddydir.name.rsplit('_', 1)
win = cls.MakeOrShow()
win.pastbrowser.OpenBuddyHistory(acctdir, acct, name, service)
MakeOrShowAndSelect = classmethod(MakeOrShowAndSelect)
if __name__ == '__main__':
from tests.testapp import testapp
a = testapp(username = 'aaron')
from path import path
dir = path('C:\\Users\\Aaron\\Documents\\Digsby Logs\\aaron\\digsby\\aaron@digsby.org\\mike@digsby.org_digsby')
PastBrowser.MakeOrShowAndSelect(dir)
a.MainLoop()